package com.collectionAndMap.collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/***
 * @ClassName: ArrayListDemo
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 14:59 2022/2/15
 * @version : V1.0
 */
public class CollectionDemo {
    public static void main(String[] args) {
        Collection<String> list = new ArrayList<>();
        list.add("菠萝");
        list.add("西瓜");
        list.add("香蕉");


        //遍历集合
        for (String s : list) {
            System.out.println(s);
        }

        //使用迭代器遍历
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }
    }
}
